package io.github.chutian0610.sqlparser.dialect

import io.github.chutian0610.sqlparser.token.CodePoint

class SQLite : Dialect {
    override fun isIdentifierPart(c: CodePoint): Boolean {
        return isIdentifierStart(c) || c.isAsciiDigit()
    }

    /**
     * See https://www.sqlite.org/draft/tokenreq.html
     */
    override fun isIdentifierStart(c: CodePoint): Boolean {
        return c.isAsciiLowercase() || c.isAsciiUppercase() || CodePoint.equalsChar(
            c,
            '_'
        ) || c.inIntRange(0x007F..0xFFFF)
    }

    /** see https://www.sqlite.org/lang_keywords.html
     *  parse `...`, [...] and "..." as identifier
     *  TODO: support depending on the context tread '...' as identifier too.
     */
    override fun isDelimitedIdentifierStart(c: CodePoint): Boolean {
        return CodePoint.equalsChar(c, '[') || CodePoint.equalsChar(c, '`') || CodePoint.equalsChar(c, '"')
    }

    override fun supportsDollarPlaceholder(): Boolean {
        return true
    }
}